package Backend.Backend_Test;

import Backend.PrinterAgent;
import Backend.PrinterAgent_bw;
import Backend.PrinterAgent_colour;
import Backend.SnmpManager;
import java.io.IOException;
import java.util.Random;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.event.ResponseListener;

public class PrinterAgentsTest {

    public static void main(String[] args) throws IOException {

        Random rand = new Random();

        // Examples of the 2 agents
        PrinterAgent_colour agent1 = new PrinterAgent_colour(rand, 0, "0.0.0.0/2001", "IET_Printer", "0345671205", 50);
        PrinterAgent_bw agent2 = new PrinterAgent_bw(rand, 1, "0.0.0.0/2002", "LG12_Printer", "0345671209", 70);

        // set up the manager with their values
        SnmpManager manager = new SnmpManager(new String[]{"udp:127.0.0.1/2001", "udp:127.0.0.1/2002"}, new String[]{"public", "public"});

        // Start the agents
        agent1.start();
        agent2.start();

        //start the manager
        manager.start();

        //get all colouted printer OIDs
        String[] arrayStrings = manager.getArrayStrings(0, PrinterAgent.colourlist);
        for (String s : arrayStrings) {
            System.out.println(s);
        }

        //get all bw printer OIDs
        arrayStrings = manager.getArrayStrings(1, PrinterAgent.bwlist);
        for (String s : arrayStrings) {
            System.out.println(s);
        }
        
        // example of grabbing a single OID
        System.out.println(manager.getString(0, PrinterAgent.localisation));
        
        // example of setting a single OID
           manager.set(0, PrinterAgent.localisation, "English_US", new ResponseListener() {
            public void onResponse(ResponseEvent event) {
                PDU strResponse;
                String result;
                ((Snmp) event.getSource()).cancel(event.getRequest(), this);
                strResponse = event.getResponse();
                if (strResponse != null) {
                    System.out.println(strResponse.getVariableBindings().firstElement().toValueString());
                }
            }
        });
    }
}
